//
//  HYSalonDetaController.m
//  KaiJing
//
//  Created by lanou on 16/1/15.
//  Copyright © 2016年 HuangZuCui. All rights reserved.
//

#import "HYSalonDetaController.h"
#import "HYSalonTableHeaderView.h"
#import "PKRequestManager.h"
#import "HYDateSalonModel.h"
#import <UIImageView+WebCache.h>

@interface HYSalonDetaController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) HYSalonTableHeaderView *headerView;
@property (nonatomic, strong) NSMutableArray *dataArray;
@property (nonatomic, strong) HYDateSalonModel *dateModel;
@end
static NSString *identifier = @"HYSalonDetaController";


@implementation HYSalonDetaController

- (void)viewDidLoad {
    [super viewDidLoad];
    _dataArray = [NSMutableArray array];
    [self setUpData];
    
}

- (void)addTableView {
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - 113) style:(UITableViewStyleGrouped)];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
   
    _headerView = [[HYSalonTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight / 2)];
    _tableView.rowHeight = 100;
    _headerView.backgroundColor = kRandomClolor;
    _tableView.tableHeaderView = _headerView;
    
          _headerView.name.text = _dateModel.name;
    NSString *threadnum = [NSString stringWithFormat:@"%@人参与",_dateModel.threadnum];
        _headerView.threadnum.text = threadnum;
    _headerView.timeLabel.text = _dateModel.createtime;
        _headerView.desc.text = _dateModel.desc;
        _headerView.founderusername.text = _dateModel.founderusername;
    NSString *icon = [NSString stringWithFormat:@"http://morguo.com/%@",_dateModel.icon];
    [_headerView.headerImageView sd_setImageWithURL:[NSURL URLWithString:icon]];
}

-(void) setUpData {
    NSString *string = [NSString stringWithFormat:@"http://morguo.com/forum.php?mod=collection&action=view&ctid=%@&androidflag=1&appfrom=ios&iosversion=3.13&page=1",_model.ctid];
    [PKRequestManager requestWithUrlString:string parDic:nil method:GET finish:^(NSDictionary *dataDic) {
        NSDictionary *dic = dataDic[@"data"];
        _dateModel = [[HYDateSalonModel alloc] init];
        [_dateModel setValuesForKeysWithDictionary:dic];
        [_dataArray addObject:_dateModel];
        
        [self addTableView];
        [_tableView reloadData];
    } error:^(NSError *error) {
        
    }];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 5;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleSubtitle) reuseIdentifier:identifier];
    }
    
    cell.backgroundColor = kRandomClolor;
    
    return cell;
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
